package br.com.k19.jpa;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

public class TestaEditoraRepository {

	public static void main(String[] args) {
		EntityManagerFactory factory = Persistence.createEntityManagerFactory("livraria_pu");
		EntityManager manager = factory.createEntityManager();
		
		EditoraRepository repo = new EditoraRepository(manager);
		List<Editora> lst = repo.getListaDeEditoras();
		
		for (Editora editora : lst) {
			System.out.println("Editora: " + editora.getNome());
		}
		
		Editora e = new Editora();
		//e.setNome("Livraria Cultura");
		//e.setEmail("cultura.fale@cultura.com");
		
		//repo.setAdiciona(e);
		
		manager.getTransaction().begin();
		manager.getTransaction().commit();
		
		lst = repo.getListaDeEditoras();
		
		for (Editora editora : lst) {
			System.out.println("Editora: " + editora.getNome());
		}
		
		e = repo.getBusca(1);
		e.setNome("Saraiva");
		e.setEmail("saraiva@adm.com");
		
		repo.setAdiciona(e);
		manager.getTransaction().begin();
		manager.getTransaction().commit();
		
		lst = repo.getListaDeEditoras();
		
		for (Editora editora : lst) {
			System.out.println("Editora: " + editora.getNome());
		}
		
	}

}
